<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/5/17
  Time: 11:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>硬盘信息</title>
</head>
<body>
<div id="hardDisk_tb">
    <input class="easyui-textbox" name="brand" data-options="label:'品牌', labelAlign:'right', labelWidth:30">
    <input class="easyui-textbox" name="capacity" data-options="label:'容量', labelAlign:'right', labelWidth:40">
    <input class="easyui-textbox" name="speed" data-options="label:'转速', labelAlign:'right', labelWidth:40">
    <a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="queryHardDisk()">查询</a>
    <br>
    <a class="easyui-linkbutton" onclick="addHardDisk()" data-options="iconCls:'icon-add',plain:true">新增</a>
    <a class="easyui-linkbutton" onclick="deleteHardDisk()" data-options="iconCls:'icon-remove',plain:true">删除</a>
    <a class="easyui-linkbutton" onclick="editHardDisk()" data-options="iconCls:'icon-edit',plain:true">修改</a>
</div>
<table id="hardDisk_dg"></table>
<script>
    $(function () {
        $('#hardDisk_dg').datagrid({
            method:'post',
            fitColumns:true,
            nowrap:true,
            fit:true,
            ctrlSelect:true,
            scrollbarSize:0,
            url:'../hardDisk/findAllHardDisks',
            columns:[[
                {field:'id',title:'id',width:25},
                {field:'brand',title:'品牌',width:25},
                {field:'capacity',title:'容量',width:25},
                {field:'speed',title:'转速',width:25}
            ]],
            pagination:true,
            toolbar:'#hardDisk_tb'
        });

        $('#hardDisk_dg').datagrid('getPager').pagination({
            beforePageText:'第',
            afterPageText:'页，共{pages}页',
            displayMsg:'当前显示第{from}到{to}条，共{total}条'
        });
    });

    function addHardDisk() {
        if ($('#tt').tabs('exists', '添加硬盘')) {
            $('#tt').tabs('select', '添加硬盘');
        } else {
            $('#tt').tabs('add', {
                title:'添加硬盘',
                closable:true,
                href:'../hardDisk/getAddHardDiskView'
            });
        }
    }

    function deleteHardDisk() {
        var row = $('#hardDisk_dg').datagrid('getSelected');
        if (row === null) {
            return;
        } else {
            $.messager.confirm({
                title: '确认',
                msg: '确定要删除吗？',
                ok:'确认',
                cancel:'取消',
                fn: function(r){
                    if (r){
                        var index = $('#hardDisk_dg').datagrid('getRowIndex', row);
                        $.ajax({
                            url:'../hardDisk/deleteHardDiskById',
                            type:'post',
                            data:'id=' + row.id,
                            dataType:'json',
                            success:function (data) {
                                //var d = eval('(' + data + ')');
                                if (data.result === 'success') {
                                    $('#hardDisk_dg').datagrid('deleteRow', index);
                                }
                                $.messager.alert('提示', data.message, 'info');
                            }
                        });
                    }
                }
            });
        }
    }

    function editHardDisk() {
        var row = $('#hardDisk_dg').datagrid('getSelected');
        if (row == null) {
            return;
        } else {
            if ($('#tt').tabs('exists', '修改硬盘')) {
                $('#tt').tabs('select', '修改硬盘');
                $('#editHardDiskForm').form('load', row);
            } else {
                $('#tt').tabs('add', {
                    title:'修改硬盘',
                    closable:true,
                    href:'../hardDisk/getEditHardDiskView'
                });
            }
        }
    }

    function queryHardDisk() {
        var data = {
            brand:$("input[name='brand']").val(),
            capacity:$("input[name='capacity']").val(),
            speed:$("input[name='speed']").val()
        };
        $('#hardDisk_dg').datagrid('load', data);
    }
</script>
</body>
</html>
